﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using DTO;
using BUS;
namespace CDT_CSDLNC
{
    public partial class ucDangSanPham : UserControl
    {
        public ucDangSanPham()
        {
            InitializeComponent();
        }

        public SanPhamDTO sp = null;
        public TinBanDTO tb = null;
        private string anhDaiDien;
        private void ucDangSanPham_Load(object sender, EventArgs e)
        {
            cbLoaiSanPham.Items.Add("Loại 1");
            cbLoaiSanPham.Items.Add("Loại 2");
            cbLoaiSanPham.Items.Add("Loại 3");
            cbLoaiSanPham.SelectedIndex = 0;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            openFileDialog1.InitialDirectory = Directory.GetParent(Directory.GetParent(Application.StartupPath).ToString()).ToString() + "\\Images\\";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                tbHinhSanPham.Text = openFileDialog1.FileName;
                FileInfo file = new FileInfo(openFileDialog1.FileName);
                anhDaiDien = file.Name;
            }
        }

        private void XuLyKichBan()
        {
            frmMain main = (frmMain)this.ParentForm;
            int flag = main.flag;
            switch (flag)
            {
                case 1:
                    main.kb1_buoc = 3;
                    main.KichBan1();
                    break;
                case 2:
                    main.kb2_buoc = 3;
                    main.KichBan2();
                    break;
                case 3:
                    main.kb3_buoc = 3;
                    main.KichBan3();
                    break;
                case 4:
                    main.kb4_buoc = 3;
                    main.KichBan4();
                    break;
            }
        }

        private void btXacNhan_Click(object sender, EventArgs e)
        {
            //lấy tin bán
            tb = new TinBanDTO();
            tb.MaSanPham = "";
            tb.MaTinBan = "";
            frmMain frm = (frmMain)this.ParentForm;
            tb.MaNguoiBan = frm.ucdangnhap.maKhachHang;
            tb.AnhDaiDien = anhDaiDien;
            tb.GiaBan = int.Parse(tbGiaBan.Text);
            //lấy sản phẩm
            sp = new SanPhamDTO();
            sp.MaSanPham = "";
            sp.TenSanPham = tbTenSanPham.Text;
            if (rbMoi.Checked == true)
                sp.TinhTrang = "Mới";
            else
                sp.TinhTrang = "Đã sử dụng";
            sp.XuatXu = tbXuatXu.Text;
            sp.MoTaChiTiet = rtbMoTaChiTiet.Text;
            sp.LoaiSanPham = cbLoaiSanPham.SelectedItem.ToString();
            XuLyKichBan();
        }


    }
}
